﻿Public Class frmRapor

    Private Sub SimpleButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton1.Click
        Dim sb As New System.Text.StringBuilder
        sb.Append("exec sp_executesql N'SELECT     STOK_HAREKETLERI.sth_tarih AS Tarih, CASE WHEN sth_normal_iade = 0 THEN ''Normal'' ELSE ''İade'' END AS [Evrak Tipi],CARI_HESAPLAR.cari_kod AS [Cari Kodu], CARI_HESAPLAR.cari_unvan1 AS [Cari Ünvan 1], CARI_HESAPLAR.cari_unvan2 AS [Cari Ünvan 2],STOK_HAREKETLERI.sth_evrakno_seri AS Seri, STOK_HAREKETLERI.sth_evrakno_sira AS Sıra, COUNT(STOK_HAREKETLERI.sth_satirno) AS Satır ")
        sb.Append(" FROM         STOK_HAREKETLERI INNER JOIN CARI_HESAPLAR ON STOK_HAREKETLERI.sth_cari_kodu = CARI_HESAPLAR.cari_kod ")
        sb.Append(" WHERE     (STOK_HAREKETLERI.sth_tip <= 1) AND (STOK_HAREKETLERI.sth_cins = 0) AND (STOK_HAREKETLERI.sth_evraktip in (1,13)) AND (STOK_HAREKETLERI.sth_giris_depo_no = {0}) AND (STOK_HAREKETLERI.sth_tarih >= CONVERT(DATETIME, ''{1} 00:00:00'', 102) AND STOK_HAREKETLERI.sth_tarih <= CONVERT(DATETIME,''{2} 23:59:59'', 102)) ")
        sb.Append(" GROUP BY STOK_HAREKETLERI.sth_tarih, CASE WHEN sth_normal_iade = 0 THEN ''Normal'' ELSE ''İade'' END, CARI_HESAPLAR.cari_kod, CARI_HESAPLAR.cari_unvan1, CARI_HESAPLAR.cari_unvan2, STOK_HAREKETLERI.sth_evrakno_seri, STOK_HAREKETLERI.sth_evrakno_sira ")
        sb.Append(" ORDER BY CARI_HESAPLAR.cari_unvan1, STOK_HAREKETLERI.sth_tarih'")
        Dim tarih1 As String = DateEdit1.DateTime.Year & "-" & DateEdit1.DateTime.Month & "-" & DateEdit1.DateTime.Day
        Dim tarih2 As String = DateEdit2.DateTime.Year & "-" & DateEdit2.DateTime.Month & "-" & DateEdit2.DateTime.Day
        Dim ds As DataSet
        UzakServis.Url = Servis_Url
        ds = UzakServis.FillDataSet(Sql_Server, Database_Name, String.Format(sb.ToString(), Depo_Kod, tarih1, tarih2))
        If ds.Tables.Count > 0 Then
            GridControl1.DataSource = ds.Tables(0)
            GridView1.BestFitColumns()
        End If
    End Sub

    Private Sub frmRapor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DateEdit1.DateTime = Now
        DateEdit2.DateTime = Now
    End Sub

    Private Sub SimpleButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton2.Click
        Dim save As New SaveFileDialog
        save.FileName = ""
        save.Filter = "Excell Dosyası|*.xls"
        If save.ShowDialog() = Windows.Forms.DialogResult.OK Then
            GridView1.ExportToExcelOld(save.FileName)
        End If
    End Sub
End Class